package com.zgzg.shop.pay.base.page.dto;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * 分页
 */
@Data
@ApiModel("分页信息")
@NoArgsConstructor
public class PageDTO<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 当前页码
     */
    @ApiModelProperty("当前页码")
    private int currentPage;
    /**
     * 每页记录数
     */
    @ApiModelProperty("每页记录数")
    private int pageSize;
    /**
     * 总页数
     */
    @ApiModelProperty("总页数")
    private int totalPages;
    /**
     * 总记录数
     */
    @ApiModelProperty("总记录数")
    private int total;
    /**
     * 列表数据
     */
    @ApiModelProperty("列表数据")
    private List<T> list;
    /**
     * 其他属性
     */
    @ApiModelProperty("其他属性")
    private Object other;
    /**
     * iPage分页
     */
    public PageDTO(IPage<T> page) {
        this.list = page.getRecords();
        this.total = (int) page.getTotal();
        this.currentPage = (int) page.getCurrent();
        this.pageSize = (int) page.getSize();
        this.totalPages = (int) page.getPages();
    }

    /**
     * 自定义分页
     *
     * @param list       列表数据
     * @param total      总记录数
     * @param currPage   当前页数
     * @param pageSize   每页记录数
     * @param totalPages 总页数
     */
    public PageDTO(List<T> list, int total, int currPage, int pageSize, int totalPages) {
        this.list = list;
        this.total = total;
        this.currentPage = currPage;
        this.pageSize = pageSize;
        this.totalPages = totalPages;
    }

    public PageDTO(List<T> list, int total, int currPage, int pageSize, int totalPages, Object other) {
        this.list = list;
        this.total = total;
        this.currentPage = currPage;
        this.pageSize = pageSize;
        this.totalPages = totalPages;
        this.other = other;
    }

}
